package com.itheima.day06;

import com.itheima.day06.Demo03.main;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class Demo06 {

    public static void main(String[] args) {
        //创建字符串
        String s="fje你kw我FDQFj你feAF他Eajf他eo2FA我FEjfew";
        //创建<Character,Integer>的HashMap对象
        Map<Character,Integer> map=new HashMap<>();
        //遍历字符串
        for (int i = 0; i < s.length(); i++) {
            //获取每一个字符
            char c=s.charAt(i);
            //判断是否包含该字符串
            if (map.containsKey(c)){
                //获取值
                Integer count=map.get(c);
                //每获取一次，次数加1
                count++;
                //存入新的map中
                map.put(c,count);
            }else{
                map.put(c,1);
            }
        }
        //遍历新的map
        Set<Character> keys=map.keySet();
        for (Character key : keys) {
            System.out.println("字符："+key+"共出现："+map.get(key));
        }
    }

}
